/********************************/
/*	Author:	gong_libin	*/
/*	Date:	2010_01_12	*/
/********************************/

#ifndef _SENDMAIL_H
#define	_SENDMAIL_H

#ifdef __cplusplus
	extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <time.h>
#include "Base64.h"

#ifndef SUCCESS
	#define	SUCCESS	0
	#define	FAILURE	1
#endif

#define	UINT		unsigned int
#define	UCHAR		unsigned char
#define	ULONG		unsigned long
#define	USHORT		unsigned short

#define	SMTP_PORT	25
#define	LOGIN_SIZE	128
#define	BUFFER_SIZE	2048

#define	CRLF		"\r\n"

#define	SMTP_MAIL_ERROR(format,args...)				do {	\
	fprintf(stderr,"[ERROR] %s %04d: ",__FILE__,__LINE__);		\
	fprintf(stderr,format,##args);					\
} while( 0 )

#define	TRANSFER_SMTP_PACKET(FUNCTION,SOCKET,PACKET,LENGTH)	do {	\
	if( FUNCTION(SOCKET,PACKET,LENGTH,0) < 0 ) {			\
		SMTP_MAIL_ERROR("%s\n",strerror(errno));		\
		close(SOCKET);						\
		return FAILURE;						\
	}								\
} while( 0 )

#define	CREATE_SMTP_PACKET(SEND,RECV,format,args...)		do {	\
	memset(SEND,'\0',BUFFER_SIZE);					\
	memset(RECV,'\0',BUFFER_SIZE);					\
	sprintf(SEND,format,##args);					\
} while( 0 )

void PrintHelp();
int GetSrcAddress(char *pszSrcAddress,char *pszUser,char *pszSmtp);

#ifdef __cplusplus
	}
#endif

#endif	/* _SENDMAIL_H */
